// asserts/component/alertBox/alert-box.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    tabObj: Object,
    alter_show: Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tabChange: function(event){
      var data = event.currentTarget.dataset;
      if(this.data.tabObj.activeIndex != data.index) {
        this.setData({
          ['tabObj.tabList['+ data.index +'].active']: true,
          ['tabObj.tabList['+ this.data.tabObj.activeIndex +'].active']: false,
          ['tabObj.activeIndex']: data.index
        });
      }
    },
    rightTab: function(detail) {
      var data = detail.detail;
      var currentTab = this.data.tabObj.tabList[this.data.tabObj.activeIndex]; //当前一级tab
      var list = currentTab.cascadeObj[currentTab.cascadeActive].subList;
      var firstIndex = this.data.tabObj.activeIndex;
      var secondIndex = currentTab.cascadeActive;
      if(data.index == 0){
        //点击全部
        if(data.item.active == false){
          //勾选全部
          for(var i = 1; i<list.length; i++) {
            list[i].active = false;
          } 
          list[0].active = true;
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj['+ secondIndex +'].subList']:list
          })
        }else {
          //取消全部勾选
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj['+ secondIndex +'].subList[0].active']: false
          })
        }
      }else{
        //点击某个
        if(data.item.active == false) {
          //勾选上，要判断是不是全部勾选
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj['+ secondIndex +'].subList['+ data.index +'].active']: true,
            ['tabObj.tabList['+ firstIndex +'].cascadeObj['+ secondIndex +'].subList['+ 0 +'].active']: false,
          })

        }else {
          //要将全部置为否
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj['+ secondIndex +'].subList['+ data.index +'].active']: false
          })
        }
      }
    },
    leftTab: function(detail) {
      var current = this.data.tabObj.tabList[this.data.tabObj.activeIndex];
      if(detail.detail.index != current.cascadeActive) {
        this.setData({
          ['tabObj.tabList['+ this.data.tabObj.activeIndex +'].cascadeObj[' + detail.detail.index + '].active']: true,
          ['tabObj.tabList['+ this.data.tabObj.activeIndex +'].cascadeObj[' + current.cascadeActive + '].active']: false,
          ['tabObj.tabList['+ this.data.tabObj.activeIndex +'].cascadeActive']: detail.detail.index
        })
      }
    },
    singleTab: function(detail) {
      var data = detail.detail;
      var firstIndex = this.data.tabObj.activeIndex;
      var currentTab = this.data.tabObj.tabList[firstIndex]; //当前一级tab
      var list = currentTab.cascadeObj;
      if(data.index == 0){
        //点击全部
        if(data.item.active == false){
          //勾选全部
          for(var i = 1; i<list.length; i++) {
            list[i].active = false;
          } 
          list[0].active = true;
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj']:list
          })
        }else {
          //取消全部勾选
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj[0].active']:false
          })
        }
      }else{
        //点击某个
        if(data.item.active == false) {
          //勾选上
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj['+ data.index +'].active']: true,
            ['tabObj.tabList['+ firstIndex +'].cascadeObj[0].active']: false,
          })
        }else {
          //要将全部置为否
          this.setData({
            ['tabObj.tabList['+ firstIndex +'].cascadeObj['+ data.index +'].active']: false
          })
        }
      }
    },
    alter_cancel: function(){
      this.triggerEvent('alterCancel', {}, {});
    },
    sure: function() {
      this.triggerEvent("selectSure", this.properties.tabObj, {});
    }
  },
  lifetimes: {
    attached: function() {
    }
  }
})
